package com.canieatit.app.network;

import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.List;

import org.apache.http.NameValuePair;
import org.apache.http.client.utils.URLEncodedUtils;
import org.apache.http.protocol.HTTP;

import android.util.Log;

public class WebServices {
	private static final String TAG = "WebServices";
	private static final String SERVICE_URL = "http://can-i-eat-it.appspot.com/product";
	
	static final int CONNECTION_TIMEOUT = 1000;
	static final int SOCKET_TIMOUT = 2000;
//	static DefaultHttpClient client = getThreadSafeClient();
	
	public static Object httpGet(final List<NameValuePair> params) throws IOException, ClassNotFoundException {
		
		String getURL = SERVICE_URL + (params != null ? "?"+URLEncodedUtils.format(params, "UTF-8"):"");
		
		Log.d(TAG, "HttpGet URL: "+ getURL);
		
		HttpURLConnection con = null;
		URL url;
		
		url = new URL(getURL);
		con = (HttpURLConnection) url.openConnection();
		con.setReadTimeout(10000 /* milliseconds */);
		con.setConnectTimeout(15000 /* milliseconds */);
		con.setRequestMethod("GET");
//			con.setDoInput(true);
		con.addRequestProperty("Accept", "application/json");
		con.addRequestProperty(HTTP.CONTENT_TYPE, "application/json");	
		// Start the query
		con.connect();
		
		InputStream is = con.getInputStream();
		
		return null;
	}

}
